package com.starhub.base.license.utils;

import java.net.NetworkInterface;  
import java.net.SocketException;  
import java.util.Enumeration;  

/**
 * 获取MAC地址Hash
 */
public class MacAddressUtil {  
    public static String getMacAddressHash() throws SocketException {  
        Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();  
        while (interfaces.hasMoreElements()) {  
            NetworkInterface network = interfaces.nextElement();  
            byte[] mac = network.getHardwareAddress();  
            if (mac != null) {  
                StringBuilder sb = new StringBuilder();  
                for (byte b : mac) {  
                    sb.append(String.format("%02X", b));  
                }  
                return Integer.toHexString(sb.toString().hashCode());  
            }  
        }  
        throw new SocketException("MAC地址无法获取");  
    }  
}
